package com.example.SearchAround_JC.jc_activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import com.example.SearchAround_JC.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2014/11/24.
 */
public class Second_Activity extends Activity {

    private Button second_back_bt;
    private TextView second_TextView;
    private ListView second_ListView;
    List<String> list = new ArrayList<String>();
    int fromFirst;
    //二级界面的数据
    String secondData[][] = {{"中餐厅","外国餐厅","快餐厅","休闲餐饮场所","咖啡厅","茶艺馆","冷饮店","蛋糕店","甜品店"}
            ,{"商场","便民商店／便利店","家电电子卖场","超级市场","花鸟鱼虫市场","家居建材市场","综合市场","文化用品店","体育用品店","特色商业街","服装鞋帽皮具店","专卖店","特殊买卖场所","个人用品/化妆品店"}
            ,{"信息咨询中心","旅行社","售票处","邮局","物流速递","电讯营业厅","事务所","人才市场","自来水营业厅","电力营业厅","美容美发店","维修站点","摄影冲印店","洗浴推拿场所","洗衣店","中介机构","搬家公司","彩票彩券销售点","丧葬设施"}
            ,{"运动场馆","高尔夫相关","娱乐场所","度假疗养场所","休闲场所","影剧院"}
            ,{"宾馆酒店","旅馆招待所"}
            ,{"公园广场","风景名胜"}
            ,{"综合医院","专科医院","诊所","急救中心","疾病预防机构","医药保健相关","动物医疗场所"}
            ,{"博物馆","展览馆","会展中心","美术馆","图书馆","科技馆","天文馆","文化宫","档案馆","文艺团体","传媒机构","学校","科研机构","培训机构","驾校"}
            ,{"飞机场","火车站","港口码头","长途汽车站","地铁站","轻轨站","公交车站","班车站","停车场","过境口岸"}
            ,{"银行","自动提款机","保险公司","证券公司","财务公司"}
            ,{"公共设施","报刊亭","公用电话","公共厕所","紧急避难场所"}
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_second);

        //接受一级菜单的条目序号
        Intent intent = getIntent();
        fromFirst = intent.getIntExtra("firstPosition",0);
        String categroyName = intent.getStringExtra("firstItemName");
        second_TextView = (TextView) findViewById(R.id.second_TextView);
        second_TextView.setText(categroyName);
        initData(fromFirst);

        second_back_bt = (Button) findViewById(R.id.second_back_bt);
        second_TextView = (TextView) findViewById(R.id.second_TextView);
        second_ListView = (ListView) findViewById(R.id.second_ListView);



//

        ArrayAdapter adapter = new SecondArrayAdapter(Second_Activity.this, R.layout.second_listview_item, list);
        second_ListView.setAdapter(adapter);

        second_back_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private class SecondArrayAdapter extends ArrayAdapter<String> {
        private int resourceId;

        public SecondArrayAdapter(Context context, int resource, List<String> objects) {
            super(context, resource, objects);
            resourceId = resource;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final String text = getItem(position);
            View view = LayoutInflater.from(getContext()).inflate(resourceId, null);

            TextView second_ListViewItem_TextView = (TextView) view.findViewById(R.id.second_ListViewItem_TextView);
            second_ListViewItem_TextView.setText(text);

            Button second_ListViewItem_back_bt = (Button) view.findViewById(R.id.second_ListViewItem_back_bt);
            second_ListViewItem_back_bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Second_Activity.this,Third_Activity.class);
                    //一级界面的子项位置
                    intent.putExtra("firstItemPosition",fromFirst);
                    //二级界面的子项position
                    intent.putExtra("secondItemPosition",position);
                    intent.putExtra("seccontCategroy",text);
                    startActivity(intent);
                    Log.d("second_listView", "点击");
                }
            });
            return view;
        }
    }

    //初始化数据
    private  void initData(int firstPositon){
        list.clear();
        //测试数据
//        list.add("中餐厅");
//        list.add("外国餐厅");
//        list.add("快餐厅");
//        list.add("休闲餐饮场所");
//        list.add("咖啡厅");
//        list.add("茶艺馆");
//        list.add("冷饮店");
//        list.add("蛋糕店");
//        list.add("甜品店");
          String arg[] = secondData[firstPositon];
            for(int i = 0;i<arg.length;i++){
                list.add(arg[i]);
            }
    }
}
